/**********************************************************************
 *
 * This code is developed for the course Informatica Industrial II
 * of Universidad Carlos III de Madrid - 2012
 * Authors: Victor González-Pacheco, Alberto Valero-Gomez
 *
 * The code is licenced under the Common Creative License,
 * Attribution-ShareAlike 3.0
 *
 * You are free:
 *   - to Share - to copy, distribute and transmit the work
 *   - to Remix - to adapt the work
 *
 * Under the following conditions:
 *   - Attribution. You must attribute the work in the manner specified
 *     by the author or licensor (but not in any way that suggests that
 *     they endorse you or your use of the work).
 *   - Share Alike. If you alter, transform, or build upon this work,
 *     you may distribute the resulting work only under the same or
 *     similar license to this one.
 *
 * Any of the above conditions can be waived if you get permission
 * from the copyright holder.  Nothing in this license impairs or
 * restricts the author's moral rights.
 *
 * It is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.
 **********************************************************************/

#include <libraries/sockets/TCPSocketServer.h>
#include <iostream>

using namespace std;

int main(void){

    try{
        TCPSocketServer server(55556);
        int sock;
        if (server.isListening())
        sock = server.accept();
            while(true){
                string recibido,enviar;
                server.connections[sock] >> recibido;
                cout << "recibido: " << recibido << endl;
                cout << "respuesta?: ";
                cin >> enviar;
                server.connections[sock] << enviar;
            }
    }catch(char const* e){
        cout << e << endl;
    }

    return 0;
}
